from IPython.display import Audio, display, HTML
import librosa
import matplotlib.pyplot as plt
import numpy as np
import os
!scp -i ~/.ssh/no_passphrase_rsa peterpaullake@35.247.37.8:/home/peterpaullake/w/widening-chords.wav widening-chords/
!scp -i ~/.ssh/no_passphrase_rsa peterpaullake@35.247.37.8:/home/peterpaullake/w/*.npy widening-chords/
widening-chords.wav 100% 117KB 346.8KB/s 00:00 mel-00000-mixed.npy 100% 98KB 290.4KB/s 00:00 mel-00000.npy 100% 98KB 575.4KB/s 00:00 mel-00001-mixed.npy 100% 98KB 1.1MB/s 00:00 mel-00001.npy 100% 98KB 1.1MB/s 00:00 mel-00002-mixed.npy 100% 99KB 1.1MB/s 00:00 mel-00002.npy 100% 99KB 1.1MB/s 00:00 mel-00003-mixed.npy 100% 100KB 1.1MB/s 00:00 mel-00003.npy 100% 100KB 1.1MB/s 00:00 mel-00004-mixed.npy 100% 100KB 1.1MB/s 00:00 mel-00004.npy 100% 100KB 1.1MB/s 00:00 mel-00005-mixed.npy 100% 101KB 1.2MB/s 00:00 mel-00005.npy 100% 101KB 1.1MB/s 00:00 mel-00006-mixed.npy 100% 101KB 1.1MB/s 00:00 mel-00006.npy 100% 101KB 1.2MB/s 00:00 mel-00007-mixed.npy 100% 102KB 1.2MB/s 00:00 mel-00007.npy 100% 102KB 1.2MB/s 00:00 mel-00008-mixed.npy 100% 103KB 1.2MB/s 00:00 mel-00008.npy 100% 103KB 1.2MB/s 00:00 mel-00009-mixed.npy 100% 103KB 1.2MB/s 00:00 mel-00009.npy 100% 103KB 1.2MB/s 00:00 mel-00010-mixed.npy 100% 104KB 1.2MB/s 00:00 mel-00010.npy 100% 104KB 1.2MB/s 00:00 mel-00011-mixed.npy 100% 105KB 1.2MB/s 00:00 mel-00011.npy 100% 105KB 1.2MB/s 00:00 mel-00012-mixed.npy 100% 105KB 1.2MB/s 00:00 mel-00012.npy 100% 105KB 1.2MB/s 00:00 mel-00013-mixed.npy 100% 106KB 1.2MB/s 00:00 mel-00013.npy 100% 106KB 1.2MB/s 00:00 mel-00014-mixed.npy 100% 106KB 1.2MB/s 00:00 mel-00014.npy 100% 106KB 1.2MB/s 00:00 mel-00015-mixed.npy 100% 107KB 1.2MB/s 00:00 mel-00015.npy 100% 107KB 1.2MB/s 00:00 mel-00016-mixed.npy 100% 108KB 1.2MB/s 00:00 mel-00016.npy 100% 108KB 1.2MB/s 00:00 mel-00017-mixed.npy 100% 108KB 1.2MB/s 00:00 mel-00017.npy 100% 108KB 1.2MB/s 00:00 mel-00018-mixed.npy 100% 109KB 1.2MB/s 00:00 mel-00018.npy 100% 109KB 1.2MB/s 00:00 mel-00019-mixed.npy 100% 110KB 1.2MB/s 00:00 mel-00019.npy 100% 110KB 1.2MB/s 00:00 mel-00020-mixed.npy 100% 110KB 1.3MB/s 00:00 mel-00020.npy 100% 110KB 1.2MB/s 00:00 wave-00001.npy 100% 156KB 1.8MB/s 00:00 wave-00002.npy 100% 157KB 1.8MB/s 00:00 wave-00003.npy 100% 158KB 1.8MB/s 00:00 wave-00004.npy 100% 159KB 1.8MB/s 00:00 wave-00005.npy 100% 160KB 1.8MB/s 00:00 wave-00006.npy 100% 161KB 1.8MB/s 00:00 wave-00007.npy 100% 162KB 1.8MB/s 00:00 wave-00008.npy 100% 163KB 1.8MB/s 00:00 wave-00009.npy 100% 164KB 1.9MB/s 00:00 wave-00010.npy 100% 165KB 1.9MB/s 00:00 wave-00011.npy 100% 166KB 1.9MB/s 00:00 wave-00012.npy 100% 167KB 1.9MB/s 00:00 wave-00013.npy 100% 168KB 1.9MB/s 00:00 wave-00014.npy 100% 169KB 1.9MB/s 00:00 wave-00015.npy 100% 170KB 1.9MB/s 00:00 wave-00016.npy 100% 171KB 1.9MB/s 00:00 wave-00017.npy 100% 172KB 1.9MB/s 00:00 wave-00018.npy 100% 173KB 2.0MB/s 00:00 wave-00019.npy 100% 174KB 1.9MB/s 00:00 wave-00020.npy 100% 175KB 2.0MB/s 00:00
RATE = 22050
def forever():
"""Generator for iterating over integers from 0 onwards."""
i = 0
while True:
yield i
i += 1
def plot_wave(ax, wave, title='', range=None):
ax.set_title(title)
if range is not None:
ax.plot(wave[range[0]:range[1]])
else:
ax.plot(wave)
def plot_mel(ax, mel, title=''):
ax.set_title(title)
pos = ax.imshow(mel.transpose(), aspect='auto', cmap='coolwarm', interpolation='nearest', origin='lower')
# fig.colorbar(pos, orientation='horizontal')
def show_wave_and_mel(wave, mel, mel_mixed=None, title=''):
n_plots = 2 if mel_mixed is None else 3
fig, axes = plt.subplots(n_plots, dpi=100, figsize=(10, 6))
plot_wave(axes[0], wave, title)
n_zoom = int(0.5 * RATE)
mid = len(wave) // 2
# plot_wave(axes[1], wave, 'Zoomed in', (mid - n_zoom // 2, mid + n_zoom // 2))
plot_mel(axes[1], mel, 'Mel spectrogram')
if n_plots == 3:
plot_mel(axes[2], mel_mixed, r'$0.6 \times$ old mel spectrogram + $0.4 \times$ new mel spectrogram')
plt.subplots_adjust(hspace=0.4)
plt.show()
display(Audio(wave, rate=RATE))
gid = 0
def show_results(name, title):
display(HTML('<h1>%s</h1>' % title))
for i in forever():
try:
if i == 0:
wave = librosa.core.load(os.path.join(name, name + '.wav'))[0]
else:
wave = np.load(os.path.join(name, 'wave-%.5d.npy' % i))
mel = np.load(os.path.join(name, 'mel-%.5d.npy' % i))
except FileNotFoundError:
break
if i == 0:
title = 'Seed audio'
else:
title = ('Audio after %d WaveNet application' + ('' if i == 1 else 's')) % i
if i == 0:
show_wave_and_mel(wave, mel, title=title)
else:
mel_mixed = np.load(os.path.join(name, 'mel-%.5d-mixed.npy' % i))
show_wave_and_mel(wave, mel, mel_mixed, title)
global gid
print('id: %d' % gid)
gid += 1
display(HTML('<hr style="height: 2px;">'))
show_results('widening-chords', 'Widening chords')
id: 0
id: 1
id: 2
id: 3
id: 4
id: 5
id: 6
id: 7
id: 8
id: 9
id: 10
id: 11
id: 12
id: 13
id: 14
id: 15
id: 16
id: 17
id: 18
id: 19
id: 20